

class Base {
    constructor(props) {}

    get = options => {
        if(options.constructor === Object){
            return this.getBase64Image(options.img, options.width, options.height);
        }
        return this.getBase64Image(options);
    };
}

Base.prototype.getBase64Image = (img, width = null, height = null) => {
    let canvas = document.createElement("canvas");
    img.width = width || img.width;
    img.height = height || img.height;
    canvas.width = img.width;
    canvas.height = img.height;
    let ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0, img.width, img.height);
    let ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
    return canvas.toDataURL("image/" + ext);
};

module.exports = {
    base : new Base()
};
